<?php
$data = json_decode(file_get_contents("php://input"), true);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // 提取前端发送的数据字段
  $teamName = $data['parsedData']['teamName'];
  $coach = $data['parsedData']['coach'];
  $groupNo = $data['parsedData']['groupNo'];
  $playerId = $data['parsedData']['playerId'];
  $teamDesc = $data['parsedData']['teamDesc'];
  $worldRank = $data['parsedData']['worldRank'];
  $winRate = $data['parsedData']['winRate'];
}

session_start();
$user_id = $_SESSION['userId'];

$addTeamSql = "insert into team(team_name,world_rank,group_no,coach,best_player_id) values('{$teamName}',$worldRank,'{$groupNo}','{$coach}',$playerId);";
// $addTeamSql = "insert into team(team_name,world_rank,group_no,coach,best_player_id,win_rate,team_desc) values('{$teamName}',$worldRank,'{$groupNo}','{$coach}',$playerId,$winRate,'{$teamDesc}');";
// $addTeamSql = "select * from team";
include('../mysqli_connect.php');
$addTeamRes = mysqli_query($dbc, $addTeamSql);

if ($addTeamRes == 1) {
  $response = array('status' => true, 'message' => '添加成功', 'wr' => $winRate);
  echo "<script>console.log('添加球员成功！')</script>";
} else {
  $response = array('status' => false, 'message' => '添加失败', 'wr' => $winRate, 'error' => mysqli_error($dbc));
  echo "<script>console.log('添加球员shibai！')</script>";
}

echo json_encode($response);
